﻿using Caliburn.Micro;
using LearnEnglishWords.UI.ViewModels;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using IBE = Common.IllegalBehaviorException;
using Common;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556

namespace LearnEnglishWords.UI.Views
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class StartView : Page
    {
        public StartView()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            IoC.Get<INavigationService>().NavigateToViewModel<WordDemostrationViewModel>();
        }

		private async void Button_Click_1(object sender, RoutedEventArgs e)
		{
			var init = new SQLite.EnWordsDbInitializer();
			init.CreateTables();

			var id = Guid.NewGuid();
			var data = "test test test test";
			var entity = new SQLite.DbEntities.TestDbEntity() { Id = id, TestData = data };
			await init.TestRepo.InsertAsync(entity);

			var all = await init.TestRepo.GetAll();

			var bla = await init.TestRepo.GetByIdAsync(id);

			if (bla.TestData != data)
				throw new IBE();

			await init.TestRepo.DeleteById(id);
			var bla2 = await init.TestRepo.GetByIdAsync(id);
			if (bla2 != null)
                throw new IBE();

            await init.TestRepo.ClearAsync();
            var bla3 = await init.TestRepo.GetAll();
            if (!bla3.IsNullOrEmpty())
                throw new IBE();

			var md = new MessageDialog("db works");
			md.ShowAsync();
		}

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            IoC.Get<INavigationService>().NavigateToViewModel<DashboardViewModel>();
        }
    }
}
